# This is the root FPTK CMakeLists file.
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)

PROJECT(FPTK)

SET(FPTK_VERSION_MAJOR "0")
SET(FPTK_VERSION_MINOR "9")
SET(FPTK_VERSION_PATCH "2")

SET(FPTK_VERSION_STRING "${FPTK_VERSION_MAJOR}.${FPTK_VERSION_MINOR}.${FPTK_VERSION_PATCH}")


# If CMake is the version we're expecting, don't show the
# CMAKE_BACKWARDS_COMPATIBILITY option. If the version is higher than the
# minimal version required, then show the backward compatibility option.
IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" MATCHES "^2\\.4$")
  MARK_AS_ADVANCED(FORCE CMAKE_BACKWARDS_COMPATIBILITY)
ELSE("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" MATCHES "^2\\.4$")
  MARK_AS_ADVANCED(CLEAR CMAKE_BACKWARDS_COMPATIBILITY)
ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" MATCHES "^2\\.4$")


SUBDIRS(Common)
SET(FPTK_LIBRARIES ${FPTK_LIBRARIES} FPTKCommon)
SET(FPTK_LIBRARY_DIR ${FPTK_LIBRARY_DIR} ${FPTK_BINARY_DIR}/Common)
SET(FPTK_INCLUDE_DIRS ${FPTK_INCLUDE_DIRS} ${FPTK_SOURCE_DIR}/Common)


OPTION(USE_ITK "ITK classes Extensions" ON)
IF(USE_ITK)
  INCLUDE (${CMAKE_ROOT}/Modules/FindITK.cmake)
  IF(USE_ITK_FILE)
    INCLUDE(${USE_ITK_FILE})
  ENDIF(USE_ITK_FILE)
  INCLUDE_DIRECTORIES( 
    ${ITK_SOURCE_DIR}/Code
    )
  SET(ITK_LIBRARIES
    ITKCommon
    ITKIO
    ITKNumerics
    ITKBasicFilters
    ITKAlgorithms
    )
  LINK_LIBRARIES(
    ${ITK_LIBRARIES}
    )
  SUBDIRS(ITK)
  SET(FPTK_LIBRARIES ${FPTK_LIBRARIES} FPTK_ITK)
  SET(FPTK_LIBRARY_DIR ${FPTK_LIBRARY_DIR} ${FPTK_BINARY_DIR}/ITK)
  SET(FPTK_INCLUDE_DIRS ${FPTK_INCLUDE_DIRS} ${FPTK_SOURCE_DIR}/ITK)
ENDIF(USE_ITK)


OPTION(USE_FLTK_LIB_EXTENSIONS "FLTK Class Extensions" ON)
IF(USE_FLTK_LIB_EXTENSIONS)
SET(HAVE_GL 0)
OPTION(USE_OPENGL "OpenGL Support" ON)
IF(USE_OPENGL)
  FIND_PACKAGE(OpenGL)
  IF(OPENGL_FOUND)
    SET(HAVE_GL 1)
  ENDIF(OPENGL_FOUND)
ENDIF(USE_OPENGL)
FIND_PACKAGE(FLTK)
IF(FLTK_FOUND)
   SUBDIRS(Fl)
   SET(FPTK_LIBRARIES ${FPTK_LIBRARIES} FPTK_Fl)
   SET(FPTK_LIBRARY_DIR ${FPTK_LIBRARY_DIR} ${FPTK_BINARY_DIR}/Fl)
   SET(FPTK_INCLUDE_DIRS ${FPTK_INCLUDE_DIRS} ${FPTK_SOURCE_DIR}/Fl)
ENDIF(FLTK_FOUND)
ENDIF(USE_FLTK_LIB_EXTENSIONS)

OPTION(USE_MATHSLIBS "Maths Libraries" ON)
IF(USE_MATHSLIBS)
  SUBDIRS(Maths)
  SET(FPTK_LIBRARIES ${FPTK_LIBRARIES} FPTKMathsLib)
  SET(FPTK_LIBRARY_DIR ${FPTK_LIBRARY_DIR} ${FPTK_BINARY_DIR}/Maths)
  SET(FPTK_INCLUDE_DIRS ${FPTK_INCLUDE_DIRS} ${FPTK_SOURCE_DIR}/Maths)
ENDIF(USE_MATHSLIBS)


#-----------------Copy the configuration files-------------------
CONFIGURE_FILE(${FPTK_SOURCE_DIR}/CMake/FPTKConfig.cmake.in
               ${FPTK_BINARY_DIR}/FPTKConfig.cmake @ONLY)
CONFIGURE_FILE(${FPTK_SOURCE_DIR}/CMake/UseFPTK.cmake.in
                ${FPTK_BINARY_DIR}/UseFPTK.cmake  COPYONLY IMMEDIATE)

#----------------Copy FindFPTK.cmake in CMake directory so it can be used by subprojects
MARK_AS_ADVANCED(INSTALL_FINDFPTK)

IF(INSTALL_FINDFPTK)
#IF(INSTALL MATCHES "1")
 # MESSAGE("install" ${INSTALL})
  SET(INSTALL_FINDFPTK "" CACHE BOOL "Installation of FindFPTK.cmake variable" FORCE)
  CONFIGURE_FILE(${FPTK_SOURCE_DIR}/CMake/FindFPTK.cmake
                ${CMAKE_ROOT}/Modules/FindFPTK.cmake  COPYONLY)
ENDIF(INSTALL_FINDFPTK)
#ENDIF(INSTALL MATCHES "1")
#SET(INSTALL 0 CACHE STRING "install")

IF(NOT EXISTS ${CMAKE_ROOT}/Modules/FindFPTK.cmake)
  OPTION(INSTALL_FINDFPTK "Install FindFPTK" ON)
ELSE(NOT EXISTS ${CMAKE_ROOT}/Modules/FindFPTK.cmake)
  OPTION(INSTALL_FINDFPTK "Install FindFPTK" OFF)
ENDIF(NOT EXISTS ${CMAKE_ROOT}/Modules/FindFPTK.cmake)

#IF(INSTALL_FINDFPTK)
 # SET(INSTALL 1 CACHE STRING "install")
  #MESSAGE("install " ${INSTALL})
#ELSE(INSTALL_FINDFPTK)
#  SET(INSTALL 2 CACHE STRING "install")
 # MESSAGE(SEND_ERROR "install " ${INSTALL})
#ENDIF(INSTALL_FINDFPTK)


#----------------set FPTK_DIR so it can be used by subprojects

SET(FPTK_DIR "${FPTK_BINARY_DIR}" CACHE INTERNAL "FPTK dir to be used by subprojects")
